<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>02_回调函数形式的ref</title>
    <link rel="shortcut icon" href="../../favicon.ico">
</head>
<body>
<div id="test"></div>

<!--引入react核心库-->
<script src="../js/react.development.js"></script>
<!--引入react-dom，用于支持react操作DOM-->
<script src="../js/react-dom.development.js"></script>
<!--引入babel，用于将jsx转为js-->
<script src="../js/babel.min.js"></script>

<script type="text/babel">
    class Demo extends React.Component {
        state = {isHot: true};

        render() {
            const {isHot} = this.state;
            return (
                <div>
                    <h2>今天天气很{isHot ? '炎热' : '凉爽'}</h2>
                    <button onClick={this.changeWeather}>点击切换天气</button>

                    <hr/>
                    <label>
                        <input ref={this.saveInput} type="text" placeholder="点击按钮提示数据"/> &nbsp;
                    </label>
                    <button onClick={this.showData}>点击我提示左侧数据</button>
                </div>
            );
        }

        saveInput = (c) => {
            this.input1 = c;
            console.log('@', c)
        }
        changeWeather = () => {
            this.setState({isHot: !this.state.isHot}, () => {
            })
        };
        // 展示右侧输入框的数据
        showData = () => {
            const {input1} = this;
            alert(input1.value)
        };
    }

    ReactDOM.render(<Demo/>, document.getElementById('test'));
</script>
</body>
</html>